<template><!--问题详情-->
    <div style="height:100%;" v-if="knowDetail">
        <navbar :title="$t('know_detail')">
            <template #left>
                <span class="iconfont icon-left head-left" @click="backToLast"></span>
            </template>
            <template #right ><!--更多-->
                <div class="drawer-icon" v-if="loginUser == knowDetail.queCreateEntId && knowDetail.queType === 'UNSOLVED'" @click="actionSheetToggle()">
                    <div class="box-14">
                        <div>
                            <em></em><em></em><em></em>
                        </div>
                        <div>{{ $t("more_text") }}</div>
                    </div>
                </div>
            </template>
        </navbar>
        <div class="content-noBottom body-content" :class="{'cur' : knowDetail.queType === 'UNSOLVED'}">
            <van-pull-refresh v-model="isRefresh" @refresh="onPulldownTop" loading-text="loading" pulling-text="" loosing-text="" style="height: 100%;">
                <van-list
                v-model="isLoading"
                :finished="finished"
                :finished-text="(finished&&total>0) ? $t('no_more') : ''"
                loding-text="loading"
                @load="getDataList"
                >
                    <div v-bind:class="{'height100' : total === 0}" v-if="knowDetail">
                        <div class="white-bg" style="padding: 16px 15px;">
                            <p class="font-size20">{{ knowDetail.title }}</p>
                            <div class="color999" style="margin-top: 3px;display: flex;align-items: center">
                                <em class="point"></em>
                                <span class="white_nowarp">{{ knowDetail.createTime | substringTime }}</span>
                                <em class="point"></em>
                                <span class="white_nowarp">{{ $t("know_from") }}{{ knowDetail.creator }}</span>
                            </div>
                            <div class="color999" style="margin-top: 3px;display: flex;align-items: center">
                                <em class="point" v-if="knowDetail.queBounty > 0"></em>
                                <span class="white_nowarp" v-if="knowDetail.queBounty > 0">{{ $t("know_bounty") }}{{ knowDetail.queBounty }}</span><!--来自/悬赏积分-->
                                <em class="point"></em>
                                <share-common class="white_nowarp" size="14" code="QUESTION" :mtp-id="knowDetail.id" :content="knowDetail.title"></share-common>
                            </div>
                        </div>
                        <div class="bottom-shadow" style="height: 1px;margin-top: -1px;"></div>
                        <div class="white-bg" style="margin-top: 12px;padding: 17px 15px;">
                            <div style="margin-bottom: 30px;" v-if="knowDetail.content || (knowDetail.files && knowDetail.files.length > 0)">
                                <p style="line-height: 22px;" v-html="$xss(knowDetail.content)" class="htmlStyle"></p>
                                <div class="img-box-03 clearfix" v-if="knowDetail" style="padding: 0">
                                    <a v-for="file in knowDetail.files" :key="file.id">
                                        <img :src="appUrl + file.url + '/' + file.fileName" alt="" :preview="knowDetail.id"/>
                                    </a>
                                </div>
                            </div>
                            <div class="font-size11 box-17 clearfix" style="margin-bottom: 10px;" v-if="inviteToAnswer && inviteToAnswer.length > 0">
                                <span class="color666">{{ $t("know_ask_instructor") }}：</span><router-link tag="span" v-for="(invitePeople, index) in inviteToAnswer" :key="invitePeople.usrEntId" :to="'/personal/' + cwnEncrypt(invitePeople.usrEntId)"><em style="color:#1f53cc;">{{ invitePeople.usrDisplayBil }}</em><em v-if="inviteToAnswer.length -1 != index">&nbsp;|&nbsp;</em></router-link>
                            </div><!--邀请人回答-->
                            <div>
                                <span class="color-box" v-bind:class="{'bgcolor-red': knowDetail.queType === 'UNSOLVED', 'bgcolor-green': knowDetail.queType === 'SOLVED'}">{{ knowListStatus[knowDetail.queType] }}</span><span class="color-box" v-if="knowDetail.queType === 'SOLVED' && knowDetail.haveTheBest === 'OK'" style="margin-left: 5px;">{{ $t("know_popular") }}</span><span v-if="knowDetail.knowCatalog"><i class="tag-icon"></i><span class="font-size11 color999">{{ knowDetail.knowCatalog.title }}</span></span><span class="font-size11 color999" style="margin-left: 10px;">{{ knowDetail.askNum }}{{ knowDetail.askNum > 1 ? $t("know_reply_num_2") : $t("know_reply_num") }}</span><!--精选/条回复-->
                            </div>
                        </div>
                        <!--已解决的类型--最佳答案部分-->
                        <ul class="white-bg bottom-shadow module-box-17" style="margin-bottom: 10px;border-top: 1px solid #e6e6e6;" v-if="knowDetail.queType === 'SOLVED'">
                            <li>
                                <div style="margin-bottom: 20px;">
                                    <span class="btn-blue btn-green"><em class="best-icon"></em>{{ $t("know_best_anwser") }}</span><!--最佳答案-->
                                </div>
                                <div class="box-15 paddinglr03">
                                    <router-link tag="span" style="width: 40px;" :to="'/personal/' +cwnEncrypt(bestAnswer.regUser.usrEntId)"><img :src="appUrl + bestAnswer.regUser.urxExtra43" alt=""/></router-link>
                                    <span class="box-08">
                                        <router-link tag="p" class="word-clamp-1 font-size15" style="margin-bottom: 7px;" :to="'/personal/' + cwnEncrypt(bestAnswer.regUser.usrEntId)">{{ bestAnswer.regUser.usrDisplayBil }}</router-link>
                                        <p class="color999 font-size11">{{ bestAnswer.createTime | formTime('', 'subTime') }}</p>
                                    </span>
                                    <span class="icon-delete-like margin-top02" :class="{'cur': bestAnswer.submitted}" style="line-height: 40px;" @click="likeHandle(bestAnswer.id,bestAnswer.submitted,-1)">{{ bestAnswer.likeCount === 0 ? '' : bestAnswer.likeCount }}</span>
                                </div>
                                <div class="font-size14" style="padding: 10px 0;">
                                    <p class="paddingLR15" style="box-sizing: border-box;" v-text="bestAnswer.content"></p>
                                    <div class="img-box-03 margin-top10 clearfix" v-if="bestAnswer.fileList && bestAnswer.fileList.length > 0">
                                        <a v-for="file in bestAnswer.fileList" :key="file.id">
                                            <img :src="appUrl + file.url + '/' + file.fileName" alt=""/>
                                        </a>
                                    </div>
                                </div>
                            </li>
                        </ul>
                        <!--FAQ的类型-->
                        <ul class="white-bg bottom-shadow module-box-17" style="margin-bottom: 10px;border-top: 1px solid #e6e6e6;" v-if="knowDetail.queType === 'FAQ'">
                            <li>
                                <div class="box-15 paddinglr03">
                                    <router-link tag="span" style="width: 40px;" :to="'/personal/' + cwnEncrypt(bestAnswer.regUser.usrEntId)"><img :src="appUrl + bestAnswer.regUser.urxExtra43" alt=""/></router-link>
                                    <span class="box-08">
                                        <router-link tag="p" class="word-clamp-1 font-size15" style="margin-bottom: 7px;" :to="'/personal/' + cwnEncrypt(bestAnswer.regUser.usrEntId)">{{ bestAnswer.regUser.usrDisplayBil }}</router-link>
                                        <p class="color999 font-size11">{{ bestAnswer.createTime | formTime('', 'subTime') }}</p>
                                    </span>
                                    <span class="icon-delete-like margin-top02 " :class="{'cur': bestAnswer.submitted}" style="line-height: 40px;" v-like="{type: 'Answer', id: bestAnswer.id, isClick: bestAnswer.submitted ? true : false}">{{ bestAnswer.likeCount === 0 ? '' : bestAnswer.likeCount }}</span>
                                </div>
                                <div class="font-size14">
                                    <p style="padding: 10px 15px 5px;box-sizing: border-box;">{{ bestAnswer.content }}</p>
                                    <div class="img-box-03 clearfix" v-if="bestAnswer.fileList && bestAnswer.fileList.length > 0">
                                        <a v-for="file in knowDetail.answer.fileList" :key="file.id">
                                            <img :src="appUrl + file.url + '/' + file.fileName" alt=""/>
                                        </a>
                                    </div>
                                </div>
                            </li>
                        </ul>
                        <!--未解决或已解决的其他答案-->
                        <div class="white-bg">
                            <p class="font-size14" style="padding: 15px;font-weight: bold;" v-if="knowDetail.queType === 'SOLVED' && total != 0">{{ $t("know_other_answers") }}</p><!--其他答案-->
                            <ul class="module-box-17" :class="{'border-top2' : knowDetail.queType === 'UNSOLVED', 'cur' : knowDetail.queType === 'SOLVED'}">
                                <li v-for="(answer, index) in answerList" :key="index">
                                    <div class="box-15 paddinglr03">
                                        <router-link tag="span" style="width: 40px;" :to="'/personal/' + cwnEncrypt(answer.regUser.usrEntId)"><img :src="appUrl + answer.regUser.urxExtra43" alt=""/></router-link>
                                        <span class="box-08">
                                            <router-link tag="p" class="word-clamp-1 font-size15" style="margin-bottom: 7px;" :to="'/personal/' + cwnEncrypt(answer.regUser.usrEntId)">{{answer.ansIsAnonymous === 'OK' ? $t('Anonymous_user') : answer.regUser.usrDisplayBil }}</router-link>
                                            <p class="color999 font-size11">{{ answer.createTime | formTime('', 'subTime') }}</p>
                                        </span>
                                        <span v-if="knowDetail.queType === 'UNSOLVED' && loginUser == knowDetail.queCreateEntId && answer.rightIndType">
                                            <span class="btn-blue" @click="setBestAnswerReply(answer.id, answer.regUser.usrEntId, knowDetail.id)"><em class="best-icon"></em>{{ $t("know_set_best_anwser") }}</span><!--设为最佳答案-->
                                        </span>
                                    </div>
                                    <div class="font-size14" style="padding: 10px 0;">
                                        <p class="paddingLR15" style="box-sizing: border-box;" v-if="textContent(answer.content, index) == false && !expand[index]" v-html="$xss(expandText(answer.content)+'...')"></p>
                                        <p class="paddingLR15" style="box-sizing: border-box;" v-if="textContent(answer.content, index) == true || expand[index]" v-html="$xss(answer.content)"></p>
                                        <div class="expand" v-if="!expand[index]" @click="exOpen(index)">
                                            <span><!--展开-->
                                                {{ $t("button_expand") }} <img src="./images/expand.png" alt="">
                                            </span>
                                        </div>
                                        <div class="img-box-03 margin-top5 clearfix" v-if="answer.fileList && answer.fileList.length > 0">
                                            <a v-for="file in answer.fileList" :key="file.id">
                                                <img :src="appUrl + file.url + '/' + file.fileName" alt="" :preview="answer.id"/>
                                            </a>
                                        </div>
                                    </div>
                                    <div  style="display: flex;align-items: center;" :style="{'justify-content': knowDetail.queType === 'UNSOLVED' || answer.discussCount && answer.discussCount > 0 ? 'space-between' : 'flex-end'}">
                                        <div class="handle-left" style="padding-left: 15px;color: #c0bfc4;" >
                                            <span v-if="answer.discussCount && answer.discussCount > 0" @click="showDiscuss(answer.id)">{{ $t("know_answer_discuss_ing", {'value': answer.discussCount}) }}</span>
                                            <span v-else-if="knowDetail.queType === 'UNSOLVED'" @click="toUserAnswer({answerId: answer.id, userEntId: answer.regUser.usrEntId, userName: answer.regUser.usrDisplayBil})">{{ $t("know_answer_discuss") }}</span>
                                        </div>
                                        <div class="handle-right">
                                            <em class="icon-delete-right-02 paddingTB10" style="padding-right: 15px;" v-if="loginUser == knowDetail.queCreateEntId"  @click="deleteReply(answer.id, answer.regUser.usrEntId, knowDetail.id)"></em><!--删除-->
                                            <div class="num-box color666 paddingTB10 icon-delete-like " :class="{'rent ' : loginUser == knowDetail.queCreateEntId, 'cur': answer.submitted}" :style="{'padding-right' : loginUser == knowDetail.queCreateEntId ? '0' : '15px'}" @click="likeHandle(answer.id,answer.submitted,index)"><!--点赞-->{{ answer.likeCount === 0 ? '' : answer.likeCount }}
                                            </div>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </van-list>
            </van-pull-refresh>
        </div>
        <div class="comment-foot" v-if="knowDetail.queType === 'UNSOLVED'" @click="writeAnwserBtn()">{{ $t("know_im_answer") }}</div><!--我来回答...-->
        <!--更多按钮的弹出 start-->
        <div class="mask-layer" @click="maskLayer()" v-if="btnToggleMask"></div>
        <ul class="actionSheet" v-if="btnToggle">
            <li @click="deleteQue(knowDetail.id)">{{ $t("know_delete_que") }}</li><!--删除问题-->
        </ul>
        <!--更多按钮的弹出 end-->
        <!--删除问题 start-->
        <!--确定删除该问题？-->
        <van-dialog
            v-model="deleteQuestionLayer"
            show-cancel-button
            :title="$t('know_delete_tips')"
            :cancelButtonText="$t('cancel')"
            :confirm-button-text="$t('sure')"
            @confirm="deleteQuestion"
            >
        </van-dialog>
        <!--删除问题 end-->
        <!--回答列表的删除回答 start-->
        <!--确定删除该回答？-->
        <van-dialog
            v-model="deleteAnswerLayer"
            show-cancel-button
            :title="$t('know_delete_tips_2')"
            :cancelButtonText="$t('cancel')"
            :confirm-button-text="$t('sure')"
            @confirm="deleteConfirm"
            >
        </van-dialog>
        <!--回答列表的删除回答 end-->
        <!--设置最佳答案 start-->
        <!--确定把该答案设为最佳答案？-->
        <van-dialog
            v-model="setBestAnswerLayer"
            show-cancel-button
            :title="$t('know_tip_set_best_anwser')"
            :cancelButtonText="$t('cancel')"
            :confirm-button-text="$t('sure')"
            @confirm="setBestAnswerConfirm"
            >
            <div class="layer-box-content">
                <p class="color999" style="font-size: 14px;">{{ $t("know_tip_set_best_anwser_1") }}</p><!--设为最佳答案后，回答通道将被关闭-->
                <p class="color999" style="font-size: 14px;">{{ $t("know_tip_set_best_anwser_2") }}</p><!--如有悬赏积分也将被扣除-->
            </div>
        </van-dialog>
        <!--设置最佳答案 end-->
        <!--您已评价过了-->
        <div class="toast-box-03" v-if="alreadyEvaluated">
            <p class="toast-box-03-title">{{ $t('know_tip_norepeat') }}</p><!--您已评价过了-->
        </div>
        <!--我来回答 start-->
        <div class="layer-box" v-if="writeAnwser">
            <navbar :title="toUserInfo ? $t('know_im_answer_title') : $t('know_im_answer_title')" :backCallback="cancelWrite">
                <template #right >
                    <span style="float: right;" class="font-size15 write-btn-right" v-if="answer.replace(/(^\s*)|(\s*$)/g, '') == '' || errors.has('tipsAnsTitle') == true">{{ $t("btn_publish") }}</span>
                    <span style="float: right;" class="font-size15 write-btn-right cur" @click="addAnwser(knowDetail.id)" v-if="answer.replace(/(^\s*)|(\s*$)/g, '') !== '' && errors.has('tipsAnsTitle') == false">{{ $t("btn_publish") }}</span>
                </template>
            </navbar>
            <div class="layer-content-box">
                <div class="title font-size15 white-bg bottom-shadow">{{ knowDetail.title }}</div>
                <div class="white-bg" style="margin-top: 12px;padding: 17px 15px;" v-if="knowDetail.content || (knowDetail.files && knowDetail.files.length > 0)">
                    <p style="line-height: 22px;" class="htmlStyle" v-html="$xss(knowDetail.content)"></p>
                    <div class="img-box-03 clearfix" v-if="knowDetail" style="padding: 0">
                        <a v-for="file in knowDetail.files" :key="file.id">
                            <img :src="appUrl + file.url + '/' + file.fileName" alt="" :preview="knowDetail.id"/>
                        </a>
                    </div>
                </div>
                <div class="add-contents-box">
                    <p class="word-title-06">{{ $t("know_answer_describe") }}</p><!--答案描述-->
                    <div class="white-bg">
                        <textarea v-validate="'tipsAnsTitle'" name="tipsAnsTitle" :placeholder="$t('know_answer_describe_tips')" v-model="answer"></textarea><!--输入你的答案...-->
                        <p class="font-size11 colorfd3 warning-red-tan warning" v-if="errors.has('tipsAnsTitle')">{{ $t("exceeded_word_range_tips", {'value': '1000'}) }}</p><!--1000-->
                    </div>
                </div>
            </div>
        </div>
        <!--我来回答 end-->
        <discuss-list :is-show-discuss-box.sync="showDiscussBox" :answer-id="answerId" :push-answer-box.sync="writeAnwser" :to-user-info.sync="toUserInfo" :is-to-comment="knowDetail.queType === 'UNSOLVED'"></discuss-list>
    </div>
</template>

<script>
import DiscussList from './DiscussList';
import ShareCommon from '../common/ShareCommon';
import {cwnEncrypt, cwnDecrypt} from '@/utils/tools';
export default {
    name: 'KnowDetail',
    components: {
        ShareCommon,
        DiscussList
    },
    data() {
        return {
            pageNo: 1, //分页页码
            total: '1', //回答列表总数
            knowDetail: {}, //问题详情
            inviteToAnswer: [], //邀请人回答
            knowListStatus: {
                UNSOLVED: this.$t('know_wait'), //待解决
                SOLVED: this.$t('know_anwsered'), //已解决
                FAQ: this.$t('know_faq') //FAQ
            },
            answerList: [], //回答列表
            bestAnswer: {}, //最佳答案
            loginUser: '', //用户id
            btnToggleMask: false, //更多遮罩层
            btnToggle: false, //更多的按钮
            deleteQuestionLayer: false, //删除问题的确认层
            deleteAnswerLayer: false, //删除回答的确认层
            setBestAnswerLayer: false, //设置最佳答案确认层
            alreadyEvaluated: false, //您已评价过了
            writeAnwser: false, //我来回答弹出层
            answer: '',
            upImages: [], //上传的图片
            fileList: [], //上传但是未提交的
            titleExpand: false, //补充内容需展开
            expand: [],
            showDiscussBox: false, //是否显示讨论框
            toUserInfo: null, //被回复人信息
            answerId: null,
            isLikeLoading: false,
            isLoading: false,
            finished: false,
            isRefresh: false
        };
    },
    methods: {
        ...{ cwnEncrypt, cwnDecrypt },
        backToLast() {
            this.$router.replace({path: '/know/relatedToMe/myQuestion'});
        },
        likeHandle(id, isLike, index) {
            if (this.isLikeLoading) {
                return;
            }
            this.isLikeLoading = true;
            this.$axios({
                method: 'POST',
                url: `/app/api/valuation/like`,
                data: {
                    isComment: false,
                    isLike: !isLike,
                    targetId: id,
                    typeEnum: 'ANSWER'
                }
            }).then(res => {
                let temp = index === -1 ? this.bestAnswer : this.answerList[index];
                if (isLike) {
                    temp.likeCount -= 1;
                } else {
                    temp.likeCount += 1;
                }
                temp.submitted = !isLike;
                this.isLikeLoading = false;
            });
        },
        toUserAnswer(data) {
            this.toUserInfo = data;
            this.writeAnwser = true;
        },
        showDiscuss(id) {
            this.answerId = id;
            this.showDiscussBox = true;
        },
        onPulldownTop() {
            this.isRefresh = true;
            setTimeout(() => {
                this.finished = false;
                this.answerList = [];
                this.pageNo = 1;
                this.getDataList();
                this.isRefresh = false;
            }, 900);
        },
        getDataList() {
            //回答的列表
            this.$axios({
                method: 'GET',
                // url: `/app/know/answers/${this.$route.params.id}`,
                url: `/app/api/trainee/know/${this.$route.params.id}/10`,
                params: {
                    pageNo: this.pageNo
                }
            }).then((res) => {
                if (res.data.results && res.data.results.length !== 0) {
                    this.answerList = [...this.answerList, ...res.data.results];
                }
                this.total = res.data.totalRecord;
                this.isLoading = false;
                this.pageNo++;
                if (this.answerList.length >= this.total) {
                    this.finished = true;
                }
            });
        },
        getKnowDetail() {
            //问题详情的内容
            this.$axios({
                method: 'GET',
                // url: `/app/know/knowDetail/json/${this.$route.params.type}/${this.$route.params.id}`
                url: `/app/api/trainee/know/detail/${this.$route.params.id}`
            }).then((res) => {
                this.knowDetail = res.data;
                this.inviteToAnswer = res.data.callUsers;
                this.bestAnswer = res.data.bestAnswer;
                // if (this.knowDetail.content) {
                //     this.titleTextContent(this.knowDetail.content);
                // }
            });
        },
        //更多的弹出层
        actionSheetToggle() {
            this.btnToggleMask = true;
            this.btnToggle = true;
        },
        //更多遮罩层
        maskLayer() {
            this.btnToggleMask = false;
            this.btnToggle = false;
        },
        //删除问题方法
        deleteQue(queId) {
            this.deleteQuestionLayer = true;
            this.deleteQueObj = {queId};
        },
        //删除问题的确认层
        deleteQuestion() {
            let {queId} = this.deleteQueObj;
            this.$axios({
                method: 'DELETE',
                url: `/app/api/trainee/know/question/${queId}`
            }).then((res) => {
                this.$store.commit('removeKeepAliveList', 'KnowIndex');
                this.$router.replace({path: '/know/relatedToMe/myQuestion'});
            });
        },
        //设置最佳答案
        setBestAnswerReply(cmtId, targetId, queId) {
            this.setBestAnswerLayer = true;
            this.setBestAnswerLayerObj = {cmtId, targetId, queId};
        },
        setBestAnswerConfirm() {
            let {cmtId, targetId, queId} = this.setBestAnswerLayerObj;
            this.$axios({
                method: 'POST',
                // url: '/app/know/setBestAnswer/' + cmtId + '/' + targetId + '/' + queId
                url: `/app/api/trainee/know/optimal`,
                data: {
                    queId: String(queId),
                    answerId: cmtId
                }
            }).then((res) => {
                this.answerList = [];
                this.pageNo = 1;
                this.getDataList();
                this.getKnowDetail();
            });
        },
        //"好"的投票百分比保留为两位小数
        goodVote(goodAnswer, answerTotal) {
            let voteResult = (((this.bestAnswer.ans_vote_for / this.bestAnswer.ans_vote_total) * 100) - parseInt(((this.bestAnswer.ans_vote_for / this.bestAnswer.ans_vote_total) * 100)) > 0) ? (((this.bestAnswer.ans_vote_for / this.bestAnswer.ans_vote_total) * 100).toFixed(2)) : ((this.bestAnswer.ans_vote_for / this.bestAnswer.ans_vote_total) * 100);
            return voteResult;
        },
        //"不好"的投票百分比保留为两位小数
        notGoodVote(notgoodAnswer, answerTotal) {
            let voteResult = (((this.bestAnswer.ans_vote_down / this.bestAnswer.ans_vote_total) * 100) - parseInt(((this.bestAnswer.ans_vote_down / this.bestAnswer.ans_vote_total) * 100)) > 0) ? (((this.bestAnswer.ans_vote_down / this.bestAnswer.ans_vote_total) * 100).toFixed(2)) : ((this.bestAnswer.ans_vote_down / this.bestAnswer.ans_vote_total) * 100);
            return voteResult;
        },
        //投票方法
        changeAnsVote(queId, goodInd) {
            this.$axios({
                method: 'POST',
                url: '/app/know/changeAnsVote/' + queId + '/' + goodInd
            }).then((res) => {
                if (res.data.evaluationInd === true) {
                    this.alreadyEvaluated = true; //弹出你已评价了
                    setTimeout(() => {
                        this.alreadyEvaluated = false;
                    }, 3000);
                } else {
                    this.$toast(this.$t('know_evaluation_success')); // 评价成功
                    this.getDataList();
                    this.getKnowDetail();
                    this.bestAnswer.ans_vote_total = res.data.answerSituation.ans_vote_total;
                    //this.good_rate = this.data.good_rate;
                    //this.not_good_rate = this.data.not_good_rate;
                }
            });
        },
        //删除回答方法
        deleteReply(ansId, ansEntId, queId) {
            this.deleteAnswerLayer = true;
            this.deleteRelpyObj = {ansId, ansEntId, queId};
        },
        //删除回答的确认层--确定
        deleteConfirm() {
            let {ansId, ansEntId, queId} = this.deleteRelpyObj;
            this.$axios({
                method: 'DELETE',
                // url: '/app/know/delThisAnswer/' + ansId + '/' + ansEntId + '/' + queId
                url: `/app/api/trainee/know/answer/` + ansId
            }).then((res) => {
                this.answerList = [];
                this.pageNo = 1;
                this.upImages = [];
                this.getKnowDetail();
                this.getDataList();
            });
        },
        //我来回答
        writeAnwserBtn() {
            this.answer = '';
            this.fileList = [];
            this.upImages = [];
            // this.alreadyFile();
            this.writeAnwser = true;
        },
        cancelWrite() {
            this.writeAnwser = false;
            this.toUserInfo = null;
        },
        addAnwser(queId) {
            this.expand = [];
            this.$validator.validate().then(res => {
                if (res) {
                    this.writeAnwser = false;
                    // let formData = new FormData();
                    // formData.append('ansContent', this.answer);
                    // formData.append('ansReferContent', '');
                    if (this.toUserInfo !== null) {
                        this.$axios({
                            method: 'POST',
                            url: `/app/api/trainee/know/save/discuss`,
                            data: {
                                ansAskEntIds: this.toUserInfo.id,
                                ansIsAnonymous: 'FAIL',
                                title: this.answer,
                                replyId: this.toUserInfo.userEntId,
                                answerId: this.toUserInfo.answerId
                            }
                        }).then((res) => {
                            this.answerList = [];
                            this.pageNo = 1;
                            this.getDataList();
                            this.getKnowDetail();
                        });
                    } else {
                        this.$axios({
                            method: 'POST',
                            // url: '/app/know/addKnowAnswer/' + queId,
                            url: `/app/api/trainee/know/save/answer`,
                            // headers: {
                            //     'Content-Type': 'multipart/form-data'
                            // },
                            // data: formData.
                            data: {
                                ansAskEntIds: '',
                                ansIsAnonymous: 'FAIL',
                                content: this.answer,
                                id: 0,
                                questionId: String(queId)
                            }
                        }).then((res) => {
                            this.answerList = [];
                            this.pageNo = 1;
                            this.getDataList();
                            this.getKnowDetail();
                        });
                    }
                    this.showDiscussBox = false;
                    this.toUserInfo = null;
                    this.answerId = 0;
                }
            });
        },
        queUpFile(event) { //上传文件
            if (['jpg', 'gif', 'jpeg', 'png'].indexOf(event.target.files[0].type.split('/')[1]) === -1) {
                this.$toast(this.$t('lab_file_tips_6')); // 图片类型必须为"jpg/jpeg/gif/png"
                return;
            }
            this.upFile(event, 'Img', 'Know', (data, type) => {
                this.upImages.push(data);
            });
            this.$refs.upFile.value = '';
        },
        queDeleteFile(index, id, type) { //删除图片
            this.deleteFile(id, type, (data, type) => {
                this.upImages.splice(index, 1);
            });
        },
        alreadyFile() {
            this.$axios({
                method: 'GET',
                url: '/app/upload/Know/noMaster'
            }).then(res => {
                for (let item of res.data.mtfList) {
                    item.mtf_url = res.data.path;
                    this.fileList.push(item);
                }
            });
        },
        expandText(text) {
            return text.slice(0, 180);
        },
        titleTextContent(value) {
            let num = 0;
            for (let i = 0; i < value.length; i++) {
                if (value.charCodeAt(i) > 127 || value.charCodeAt(i) === 94) {
                    num += 2;
                } else {
                    num += 1;
                }
            }
            if (num > 360) {
                this.titleExpand = true;
            } else {
                this.titleExpand = false;
            }
        },
        textContent(value, index) {
            let num = 0;
            for (let i = 0; i < value.length; i++) {
                if (value.charCodeAt(i) > 127 || value.charCodeAt(i) === 94) {
                    num += 2;
                } else {
                    num += 1;
                }
            }
            if (num > 360) {
                return false;
            } else {
                this.expand[index] = true;
                return true;
            }
        },
        exOpen(index) {
            this.$set(this.expand, index, true);
        }
    },
    mounted() {
        this.getKnowDetail();
        this.getDataList();
        //获取id
        this.loginUser = window.localStorage.getItem('loginUser');
        this.initPreviewRepair();
    },
    created() {
        this.$Validator.extend('tipsAnsTitle', {
            validate(value) {
                let num = 0;
                for (let i = 0; i < value.length; i++) {
                    if (value.charCodeAt(i) > 127 || value.charCodeAt(i) === 94) {
                        num += 2;
                    } else {
                        num += 1;
                    }
                }
                if (num > 2000) {
                    return false;
                } else {
                    return true;
                }
            }
        });
    }
};
</script>

<style scoped lang="less">
    .body-content.cur {
        height: calc(100% - 56px);
    }
    .module-box-17.cur {
        /*margin-top: -15px;*/
        border-top: 1px solid #e6e6e6;
    }
    .module-box-17.cur > li {
        padding: 20px 0 17px;
    }
    .module-box-17 > li {
        padding: 30px 0;
        border-bottom: 1px solid #e6e6e6;
    }
    .module-box-17 > li:nth-last-child(1) {
        border-bottom: 0;
    }
    .paddinglr03 {
        padding: 0 15px;
    }
    .box-15 {
        display: flex;
        flex-direction: row;
    }
    .box-15 img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
    }
    .box-08 {
        width: 50px;
        margin: 0 15px;
    }
    .img-box-03 {
        padding: 0 7px 0 15px;
        box-sizing: border-box;
    }
    .img-box-03 a {
        float: left;
        width: calc((100% - 22px) / 3);
        margin: 7px 7px 0 0;
        height: 110px;
    }
    .img-box-03 a img {
        width: 100%;
        height: 110px;
    }
    .comment-foot {
        box-sizing: border-box;
        padding: 0 15px;
        line-height: 55px;
        font-size: 14px;
    }
    .evaluation-box {
        padding: 20px 15px;
        background: #fafafa;
    }
    .actionSheet {
        width: 100%;
        background: #ffffff;
        padding: 10px 0;
        position: absolute;
        bottom: 0;
        left: 0;
        z-index: 505;
    }
    .actionSheet li {
        padding: 10px 15px;
        font-size: 16px;
    }
    .margin-top02.icon-delete-like:before {
        margin-top: 10px;
    }
    .box-17 span {
        line-height: 15px;
        display: inline-block;
    }
    .expand{
        width: 100%;
        text-align: center;
        color: #1a1a1a;
        margin-top: -50px;
        height: 50px;
        line-height: 80px;
        background: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
        background: -webkit-linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1));
        position: relative;
    }
    .layer-box {
        overflow-y: hidden;
    }
    .layer-header-box {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 99;
    }
    .layer-content-box {
        padding-top: 57px;
        overflow-y: auto;
        height: calc(100% - 57px);
    }
    p.htmlStyle {
        /deep/ * {
            width: 100% ;
            height: auto;
        }
    }
    .drawer-icon{
        width: auto!important;
        padding-right: 5px;
        span{
            white-space: nowrap;
        }
    }
    .white_nowarp{
        width: 40%;
        white-space: nowrap;
    }
    .layer-box-content{
        line-height: 20px;
    }
    /deep/.van-dialog__content {
        padding: 0px 48px 30px;
    }
</style>
